﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DBService
{
	public partial class DlgSendMessage : System.Windows.Forms.Form
	{
		private DbUser User { get; set; }

		public DlgSendMessage(DbUser user)
		{
			this.User = user;
			this.InitializeComponent();
		}

		private void btnSent_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.cbxUser.SelectedItem is DbUser)
				{
					if (this.rtbMessage.Text.Trim() == "")
					{
						MessageBox.Show("信息不能为空。");
					}
					else
					{
						DbUser dbUser = this.cbxUser.SelectedItem as DbUser;
						this.User.SendMessage(dbUser.Name, this.rtbMessage.Text);
						MessageBox.Show("发送成功。");
						base.DialogResult = DialogResult.Cancel;
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void DlgSentMessage_Load(object sender, EventArgs e)
		{
			foreach (DbUser item in DbUser.GetAllUsers(BimServerDB.Default))
			{
				this.cbxUser.Items.Add(item);
			}
			if (this.cbxUser.Items.Count > 0)
			{
				this.cbxUser.SelectedIndex = 0;
			}
		}
	}
}
